package com.mdr.imedera.handler;

import com.mdr.imedera.exception.wx.AccessTokenException;
import com.mdr.imedera.exception.wx.MatrialException;
import com.mdr.imedera.util.RequestResult;
import com.mdr.imedera.util.wx.AccessTokenErrCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @PACKAGE_NAME: com.mdr.imedera.handler
 * @NAME: wxb
 * @USER: Administrator
 * @DATE: 2020/10/22
 * @TIME: 12:51
 * @YEAR: 2020
 * @MONTH: 10
 * @MONTH_NAME_SHORT: 10月
 * @MONTH_NAME_FULL: 十月
 * @DAY: 22
 * @DAY_NAME_SHORT: 周四
 * @DAY_NAME_FULL: 星期四
 * @HOUR: 12
 * @MINUTE: 51
 * @PROJECT_NAME: imedera
 * @Description: 处理弹框显示异常。回复异常的编码及信息。Json 字符
 **/
@Slf4j
@Component
@RestControllerAdvice
public class AlertExceptionHandler extends RuntimeException {

    /**
     * 获取access_token 的异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(value = AccessTokenException.class)
    private RequestResult handlerException(AccessTokenException e){
        int errcode = Integer.parseInt(e.getErrcode());
        return RequestResult.failure(AccessTokenErrCode.of(errcode));
    }

    @ExceptionHandler(value = MatrialException.class)
    private RequestResult handlerException(MatrialException e){
        int errcode = Integer.parseInt(e.getErrcode());
        return RequestResult.failure(AccessTokenErrCode.of(errcode));
    }

}
